package com.boot.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.boot.entity.User;
import com.boot.service.IUserService;
import com.boot.util.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {

    @Autowired
    IUserService userService;

    @GetMapping("/user/list")
    public String list(@RequestParam(defaultValue = "1")Integer current,@RequestParam(defaultValue = "10")Integer pageSize){
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        IPage<User> iPage = new Page<>(current,pageSize);
        IPage<User> page = this.userService.page(iPage,queryWrapper);


        return ResultUtils.success(page);
    }

    @PostMapping("/user/save")
    public String save(@RequestBody User user){
        userService.save(user);
        return ResultUtils.success(true);
    }

    @PostMapping("/user/del/{id}")
    public String del(@PathVariable("id") Long id){
        userService.removeById(id);
        return ResultUtils.success(true);
    }

}
